import {AiImage} from "./core/AiImage.ts";
import {AiGlobalConfig} from "./AiGlobalConfig.ts";
import {InnerEditor} from "../core/AiEditor.ts";
import { CustomAiImage } from "./custom/CustomAiImage.ts";

export class AiImageManager {

    private static images: Record<string, AiImage> = {};

    static init(editor: InnerEditor, globalConfig: AiGlobalConfig) {
        if (globalConfig && globalConfig.images) {
            for (let key of Object.keys(globalConfig.images)) {
                switch (globalConfig.images[key].imageType) {
                    case "custom":
                        this.set(key, new CustomAiImage(key, editor, globalConfig))
                        break;
                    default:
                        break;
                }
            }
        }
    }

    static get(imageName: string): AiImage {
        if (!imageName || imageName === "auto") {
            imageName = Object.keys(this.images)[0];
        }
        return this.images[imageName];
    }

    static set(imageName: string, aiImage: AiImage) {
        this.images[imageName] = aiImage;
    }

}